        TITL DAI FIRMWARE 0E1F5-0E400  V1.1
        ORG   :E1F5
*
*
*
*********************
* RUN basiccmd EDIT *
*********************
*
* The editbuffer is set up by moving the program
* to the end of the free RAM space. All memory
* between heapstart and textbegin is used as
* editbuffer.
* On break + space: The edited area is deleted
* from the textbuffer and the program is moved
* to just after the end of the edited text by
* changing the heapsize.
* EFSW is set for input from editbuffer.
*
REDIT   CALL  :E265     Init. edit buffer
        CALL  :E19F     List into edit buffer
RED05   XRA   A
        STA   :0131     Set output to screen
        STA   :02B9     Enable complete keyb.scan
        CALL  :DD75     0 on end of buffer
        LXI   H,:0000
        SHLD  :00B4     Clear tab table pntr
        RST   5         Init screen editor
        DATA  :2A
RED10   CALL  :D6BE     Get char from keyboard
        JC    :E21B     If break pressed
        JZ    :E20D     Wait for inputs
        RST   5         Obey character
        DATA  :2D
        JMP   :E20D     Get next input
 REM
* If Break pressed:
 REM
RED19   MVI   A,:0C
        RST   5         Clear screen
        DATA  :03
RED20   CALL  :D6BE     Get char from keyboard
        JC    :E24D     If again Break
 REM
* Break followed by any character:
 REM
        JZ    :E21F     Wait for a char typed in
        MVI   A,:02
        STA   :0135     EFSW: input from buffer
        LHLD  :011B     Get end listed area
        XCHG            in DE
        LHLD  :0119     Get start listed area
        CALL  :DE1A     Calc. length listed area
        NOP
        CALL  :C9D1     Delete edited area in txtbuf
        LHLD  :029B     Get start HEAP
        XCHG            in DE
        LHLD  :00A4     Get input pntr editbuf
        CALL  :DE1A     Calc length used edit area
        INX   H
        INX   H
        XCHG            DE: length edit area +2
        CALL  :D195     Program to end of editbuf
        ORA   A         No special conditions
        RET
 REM
* Break followed by 2nd break:
 REM
RED30   CALL  :DECA     Restore original Heap +
 REM program buffers
        ORA   A         No special conditions
        RET
        NOP
*
******************************
* RUN basiccmd EDIT <linenr> *
******************************
*
REDI1   CALL  :E265     Init edit buffer
        CALL  :E1AA     List one line
        JMP   :E1FB     Into Run edit
*
*****************************
* RUN basiccmd EDIT <range> *
*****************************
*
REDI2   CALL  :E265     Init edit buffer
        CALL  :E1B6     List part of program
        JMP   :E1FB     Into Run edit
*
****************************
* INITIALISE SCREEN EDITOR *
****************************
*
* Sets up a mode 0 screen, clears all variables
* and arrays. Moves Basic program to top of free
* memory, initialises edit pointers.
*
* Exit: BC preserved. AFDEHL corrupted.
*
REDIN   MVI   A,:FF
        RST   5         Change screen to mode 0
        DATA  :18
        CALL  :D86D     Run 'OUT OF MEMORY' error
 REM if insufficient space. Else
 REM empty HEAP + variables
        CALL  :EB51     Calc free RAM space
        XCHG            in DE
        LHLD  :029D     Get HEAPsize
        DAD   D
        XCHG            Total 'free' RAM in DE
        CALL  :D195     Program to end free RAM
        LHLD  :029F     Get startaddr. textbuf
        DCX   H
        DCX   H         Minus 2
        SHLD  :00A6     Store end available space
        LHLD  :029B     Get startaddr HEAP
        INX   H
        INX   H         Plus 2
        SHLD  :00A2     Store startaddr. editbuf
        SHLD  :00A4     Set input pntr editbuf
        LXI   H,:0131
        MVI   M,:02     Set output to editbuf
        RET
 REM
**************************
* INPUT FROM EDIT BUFFER *
**************************
*
* Entry: A=0, CY=0.
*
IFBNL   PUSH  PSW
        LHLD  :00A2     Get startaddr. editbuf
        SHLD  :0132     Store it in EFEPT
IFB10   MOV   A,M       Get char from editbuf
        ORA   A         Char is 0?
        JZ    :E2AA     Then editbuf empty
        INX   H
        CPI   :0D       Car.ret?
        JNZ   :E298     Get next char if not
 REM
* If char is car.ret:
 REM
        SHLD  :00A2     Update startaddr. editbuf
        MVI   C,:00     1st pos on line
        POP   PSW       No special action
        RET
 REM
* If buffer empty:
 REM
IFB20   STA   :0135     Set input from keyboard
        CALL  :DECA     Organise HEAP + buffers
        POP   PSW       special action
        STC             CY=1
        RET
*
**********************
* RUN basiccmd PRINT *
**********************
*
* Entry: BC: Position in textbuffer.
*
RPRINT  LDAX  B         Get length
        INX   B
        MOV   D,A       Count of expr in D
        ORA   A
        JZ    :E2F7     Jump if only car.ret
RPR10   PUSH  D         Save nr of expressions
        LDAX  B         Get expr type
        INX   B
        CPI   :20
        JZ    :E2D2     Jump if string
 REM
* If INT/FPT number:
 REM
        CPI   :00
        CALL  :E808     Eval expr. Result in MACC
        PUSH  PSW       Save flags on expr.type
        CNZ   :DB53     If INT: print INT number
        POP   PSW
        CZ    :DB59     If FPT: print FPT number
        JMP   :E2E3
 REM
* If string:
 REM
RPR40   CALL  :E791     Evaluate string expr
        PUSH  H
        RST   5         Ask cursor pos and size
        DATA  :0C       char screen
        MOV   A,E       X-size of screen in A
        SUB   L         Minus X-coord cursor pos
        INR   A         +1
        POP   H
        CMP   M         (not used further: off
        NOP             screen printing possible)
        NOP             (should be: CC :DD5E)
        NOP
        CALL  :DB32     Print string pntd by HL
*
RPR50   LDAX  B         Get byte after string
        INX   B
        CPI   :FF       End marker?
        JZ    :E2F6     Then quit with car.ret
        CPI   :3B       ';' ?
        CNZ   :DB0D     Cursor to next column if
 REM not (must be ',')
        POP   D         Get nr of expr to print
        DCR   D         Update expr count
        JNZ   :E2BA     Loop if more expressions
        ORA   A         No special action
        RET
 REM
* If end of print statement:
 REM
RPR70   POP   D
RPR80   CALL  :DD5E     Print 'CR'
        ORA   A
        RET
*
**********************
* RUN basiccmd INPUT *
**********************
*
* Runs an input statement with a prompt ('?').
* RINPQ:  Input with a string.
* RINPUT: Input without a string.
*
RINPQ   CALL  :E791     Evaluate stringexpression
        CALL  :DB32     Print string pntd by HL
RINPUT  LXI   H,:0002
        DAD   SP
        CALL  :E447     Update ERSSF, print '?' and
 REM ask for inputs
        CNC   :E364     If no break: store inputs
        PUSH  PSW       Save last input
        XRA   A
        STA   :0117     Reset flag running inputs
        POP   PSW       Get last input
        JC    :E320     Abort if break
        INR   E
        JZ    :E31E     Quit if correct nr of inputs
        CALL  :DAFF     Else: Print
        DBL   :D208     'SOME INPUT IGNORED'
RIP10   ORA   A         No special action
        RET
 REM
* If suspended:
 REM
RIP20   MVI   A,:02     Code 'cmd broken in'
        RET
*
*********************
* RUN basiccmd READ *
*********************
*
RREAD   MVI   A,:01
        STA   :0135     Set input from string
        LDA   :0123     Get offset next char to en-
        MOV   E,A       code and store it in E
        LHLD  :0291     Get DATAQ addr
        MOV   A,M       Get length of string
        STA   :0134     Store it in EFECT
        INX   H         Pnts to 1st char
        SHLD  :0132     Addr 1st char in EFEPT
        CALL  :E364     Store data
        MOV   A,E       Get offset next char
        STA   :0123     Store it
        LHLD  :0132     Get EFEPT
        DCX   H         Pnts to next dataline
        SHLD  :0291     Store it in DATAQ
        XRA   A
        STA   :0135     Set input from keyboard
        RET
*
*********************
* DATA - (not used) *
*********************
*
L0E351  DATA  :21
        DATA  :01
        DATA  :60
        DATA  :69
        DATA  :22
        DATA  :1F
*
*****************
* RESTART INPUT *
*****************
*
* Error handling if running inputs.
*
INPRS   LHLD  :011D     Get saved stackpntr
        SPHL            Reload stackpntr
        LHLD  :0102     Get start current command
        MOV   B,H       ) Store it in BC
        MOV   C,L       )
        CALL  :DAFF     Print 'RETYPE LINE'
        DBL   :DB93
        JMP   :C87F     Re-execute input statement
*
**********************************
* STORE DATA IN CORRECT LOCATION *
**********************************
*
* Entry L0E56 not used.
*
* Stores data read from datastatements or gotten
* from an input line on the correct location.
*
* Entry: E : Offset next character to encode
*            (#0291).
*        HL: Startaddress data line.
*
L0E56   CALL  :E436     (not used)
*
RRDIP   LDAX  B         Get nr of data reqd
        INX   B
        MOV   D,A       Into D
RRI10   DCR   D
        JM    :E3C1     Jump if ready
RRI20   INR   E         Offset nex char
        JZ    :E3A8     Jump if at end of line
        DCR   E
RRI30   CALL  :E963     Get varptr in HL
        PUSH  B
        PUSH  D
        MOV   C,E       Offset in C
        PUSH  H         Save varptr
        LXI   H,:013E   Startaddr EBUF
        PUSH  H         Save it on stack
        ANI   :30
        RST   1         Encode a constant
        DATA  :06
        MOV   E,C       Offset in E
        POP   B
        POP   H         Get varptr
        CPI   :20       String type ?
        MOV   A,E       Offset in A
*
****************************
* STORE DATA (READ, INPUT) *
****************************
*
* Handle string inputs (no change):
*
        CZ    :E4B8     ] Only JZ :E3A2 replaced
        CNZ   :E4B4     ] by its contents
 REM
* Check separator/terminator:
 REM
RRI40   MOV   C,A       Offset in C
        CALL  :DDD2     Get char from line, neglect
 REM tab and space
        INR   C         Offset +1
        CPI   :2C       ',' ?
        JZ    :E399
        CPI   :0D       CR ?
        MVI   C,:FF     Dummy offset for end of
 REM line
RRI50   POP   D
        MOV   E,C       Offset in E
        POP   B
 REM
* Error exit changed: Now checks if end of input
* is reached. EFEPT is only updated if not running
* inputs (anymore).          
 REM
        JZ    :E367     ] Read next data if no error
        LDA   :0117     If error: Get 'run-input'
 REM flag
        CALL  :E3C3     ]
        JMP   :DA0B     ] Run 'SYNTAX ERROR'
 REM
* If end of line reached ('CR'):
 REM
RRI70   LDA   :0117     Get flag for running inputs
        ORA   A
        JZ    :E3BB     Quit if not running inputs
        CALL  :DD55     Cursor to begin next line
        CALL  :E3D0     Print '?', read input line
        JC    :E3C2     Abort if break pressed
        JMP   :E370     Cont reading
 REM
* If whole line read:
 REM
RRI80   CALL  :E3DC     Find next dataline in txtbuf
        JMP   :E370     Cont reading
 REM
* If reading done:
 REM
RRI90   ORA   A         No special action
RRI99   RET
 REM
* If error:
 REM
*
        ANA   A         ] Set flags
        RNZ             ] Abort if running inputs
        LHLD  :0132     Get EFEPT
        LXI   D,:FFFC
        DAD   D         -4
        SHLD  :0100     Set start current line
        RET
*
**************************
* PREPARE GETTING INPUTS *
**************************
*
* Continuation of 0E447.
* Prints a prompt ('?') on the screen and gets a
* textline from input.
*
INPGT   PUSH  D
        RST   5         Ask cursor pos. and size
        DATA  :0C       char. screen
        POP   D
        MVI   A,:3F
        CALL  :C6A0     Print '?'; input a textline
        MOV   E,L
        INR   E         E pnts after last char of
 REM input
        RET
*
************************************
* FIND NEXT DATALINE IN TEXTBUFFER *
************************************
*
DATAF   PUSH  PSW
        PUSH  D
        PUSH  H
        LHLD  :0124     Get addr current dataline
DTF10   MOV   A,M       Get length data string
        ORA   A
        MVI   A,:02
        JZ    :D9F5     Run error 'OUT OF DATA' if
 REM no data available
        MOV   D,H       ) Addr dataline in DE
        MOV   E,L       )
        CALL  :DE39     Calc end dataline
        SHLD  :0124     Store it in DATAP
        XCHG            End in DE, start in HL
        INX   H
        INX   H
        INX   H         Pnts to token
        MOV   A,M       Get token
        CPI   :A2       Is it DATA?
        XCHG
        JNZ   :E3E2     Check next textline if not
        XCHG
        JMP   :E436     Continu
*
        DATA  :FF
*
*
*
        END
